//Programs TABLE2A and TABLE2B produce the results in TABLE 2.
//The programs are intended to be run in tandem, with program A run first.
//It takes approximately 35 minutes on a laptop to run 10,000 iterations.

clear
set more off
drop _all
log using "\\file\UsersW$\wrr15\Home\My Documents\My Files\HURWICZ BIAS\REVISION FOR ECONOMIC MODELLING\PROGRAMS2\TABLE2.smcl", replace
etime, start
set seed 13

matrix medLRP = J(5,3,0)
matrix confidLRP = J(5,6,0)
matrix meanRR = J(5,3,0)

local i = 1
foreach betay in 0.60 0.70 0.80 0.90 0.95 {
   local j = 1
   foreach smallobs in 10 50 1000 {
      simulate LRP = r(LRP) pLRP = r(pLRP), ///
         reps(10000): ARDLprog, betay(`betay') smallobs(`smallobs') bigobs(1100) ///
		 beta0(0)  betax(1)
      summ LRP, detail
      matrix medLRP[`i', `j'] = r(p50)
      matrix confidLRP[`i', (`j'-1)*2+1] = r(p5)
      matrix confidLRP[`i', (`j'-1)*2+2] = r(p95)
	  generate RejectRate = 0
      replace RejectRate = 1 if pLRP < 0.05  
	  summ RejectRate, meanonly
      matrix meanRR[`i', `j'] = r(mean)
      local `++j'
   }
   local `++i'
}
matrix colnames medLRP = "T10(P50)" "T50(P50)" "T1000(P50)" 
matrix rownames medLRP= B60 B70 B80 B90 B95
matrix colnames confidLRP = "T10(P5)" "T10(P95)" "T50(P5)" "T50(P95)" ///
                             "T1000(P5)" "T1000(P95)"
matrix rownames confidLRP= B60 B70 B80 B90 B95
matrix colnames meanRR = T10 T50 T1000
matrix rownames meanRR = B60 B70 B80 B90 B95
matrix list medLRP
matrix list confidLRP
matrix list meanRR
etime

log close
